#pragma once

#include <functional>
#include <vector>
#include <stdlib.h>
#include <ctime>
#include <iostream>
#include <unistd.h>

using task_t= std::function<void()>;

class TaskManager
{
public:
    TaskManager()
    {
        srand(time(nullptr));
        _tasks.push_back([](){
            std::cout<<"进程："<<getpid()<<" "<<"数据库工作"<<std::endl;
        });

        _tasks.push_back([](){
            std::cout<<"进程："<<getpid()<<" "<<"前端工作"<<std::endl;
        });

        _tasks.push_back([](){
            std::cout<<"进程："<<getpid()<<" "<<"后端工作"<<std::endl;
        });

        _tasks.push_back([](){
            std::cout<<"进程："<<getpid()<<" "<<"运维工作"<<std::endl;
        });
    }

    int SelectTask()
    {
        return rand()% _tasks.size();
    }

    void Execute(int num)
    {
        if(num>= _tasks.size() || num<0 ) return ;

        _tasks[num]();
    }



private:
    std::vector<task_t> _tasks;
};


TaskManager tm;
